﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Orf.Model;
using System.Windows.Forms;

namespace Orf.dto
{
    public class huaJaShoufeiDAO
    {
        SqlHelper sqlhelper = null;
        public huaJaShoufeiDAO()
        {
            sqlhelper = new SqlHelper();
        }

        /// <summary>
        /// 获取病人的基本信息和处方信息，传入的是门诊号码和信息类型（1：基本信息，2：处方信息）
        /// </summary>
        /// <param name="ghmcClass">实体类：门诊号码</param>
        /// <param name="intType">信息类型</param>
        /// <returns></returns>
        public DataTable GetShouFeiInfo(MZ_GHMX ghmcClass, int intType)
        {
            DataTable dt = null;
            try
            {
                string strSql = "pro_guahaoBasicInfo";
                SqlParameter[] paras = new SqlParameter[]{
                     new SqlParameter("@mzhm",ghmcClass.mZHM),
                     new SqlParameter("@intType",intType)};
                dt = new DataTable();
                dt = sqlhelper.ExecuteQuery(strSql, paras, CommandType.StoredProcedure);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
            return dt;
        }

        /// <summary>
        /// 获取所有相关的门诊号码与病人姓名
        /// </summary>
        /// <returns></returns>
        public DataTable GetAllMzhm()
        {
            DataTable dt = null;
            try
            {
                string strSql = "select a.mzhm as 门诊号码,b.brxm as 病人姓名 from  mz_ghmx a left join mz_brda b on a.bahm=b.bahm";
                dt = new DataTable();
                dt = sqlhelper.ExecuteQuery(strSql, CommandType.Text);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
            return dt;
        }

        /// <summary>
        /// 根据输入的门诊号码进行模糊查询
        /// </summary>
        /// <param name="ghmxClass"></param>
        /// <returns></returns>
        public DataTable GetMzhmByInput(MZ_GHMX ghmxClass)
        {
            DataTable dt = null;
            try
            {
                string strSql = "select a.mzhm as 门诊号码,b.brxm as 病人姓名 from  mz_ghmx a left join mz_brda b on a.bahm=b.bahm where a.mzhm like ''+@mzhm+'%'";
                SqlParameter[] paras = new SqlParameter[]{
                     new SqlParameter("@mzhm",ghmxClass.mZHM)};
                dt = new DataTable();
                dt = sqlhelper.ExecuteQuery(strSql, paras, CommandType.Text);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
            return dt;
        }
        /// <summary>
        /// 获取总金额和各种处方的金额数
        /// </summary>
        /// <param name="ghmxClass"></param>
        /// <returns></returns>
        public DataTable GetFy_fromview(MZ_GHMX ghmxClass)
        {
            DataTable dt = null;
            try
            {
                string strSql = "proc_mz_cost_list";
                SqlParameter[] paras = new SqlParameter[]{
                     new SqlParameter("@mzhm",ghmxClass.mZHM)};
                dt = new DataTable();
                dt = sqlhelper.ExecuteQuery(strSql, paras, CommandType.StoredProcedure);

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
            return dt;
        }

        /// <summary>
        ///获取发票号码
        /// </summary>
        /// <param name="empClass"></param>
        /// <param name="intType"></param>
        /// <returns></returns>
        public DataTable Get_Fphm(DIC_YGDM empClass, int intType)
        {
            DataTable dt = null;
            try
            {
                string strSql = "proc_GetFphm";
                SqlParameter[] paras = new SqlParameter[]{
                     new SqlParameter("@emp_sn",empClass.yGDM),
                new SqlParameter("@intType",intType)};
                dt = new DataTable();
                dt = sqlhelper.ExecuteQuery(strSql, paras, CommandType.StoredProcedure);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
            return dt;
        }

        /// <summary>
        /// 更新表MZ_WJWH的字段SYHM的值
        /// </summary>
        /// <param name="empClass"></param>
        /// <param name="intType"></param>
        public void Update_Fphm(DIC_YGDM empClass, int intType)
        {
            int res = 0;
            try
            {
                string strSql = "proc_GetFphm";
                SqlParameter[] paras = new SqlParameter[]{
                     new SqlParameter("@emp_sn",empClass.yGDM),
                new SqlParameter("@intType",intType)};
                res = sqlhelper.ExecuteNonQuery(strSql, paras, CommandType.StoredProcedure);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
            if (res >= 0)
            {
                return;
            }
            else
            {
                MessageBox.Show("发票号更新失败！");
            }
        }

        /// <summary>
        /// 插入发票号码到处方01中
        /// </summary>
        /// <param name="cf01Class"></param>
        public void Insert_Cf01(MZ_CF01 cf01Class)
        {
            int res = 0;
            try
            {
                string strSql = "update mz_cf01 set fphm=@fphm where mzhm=@mzhm";
                SqlParameter[] paras = new SqlParameter[]{
                     new SqlParameter("@fphm",cf01Class.fPHM),
                new SqlParameter("@mzhm",cf01Class.mZHM)};
                res = sqlhelper.ExecuteNonQuery(strSql, paras, CommandType.Text);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
            if (res >= 0)
            {
                return;
            }
            else
            {
                MessageBox.Show("插入发票号码到表MZ_CF01失败！");
            }
        }
        /// <summary>
        /// 插入收费明细信息
        /// </summary>
        /// <param name="sfmxCalss"></param>
        /// <returns></returns>
        public int Insert_Sfmx(MZ_SFMX sfmxCalss)// MZ_SFMX为收费明细实体类
        {
            int res = 0;
            try
            {
                string strSql = "proc_insertSfmx";//proc_insertSfmx为存储过程，传入的参数是发票号码，门诊号码和操作员工号
                SqlParameter[] paras = new SqlParameter[]{//采用参数化传值
                     new SqlParameter("@fphm",sfmxCalss.fPHM),
                     new SqlParameter("@mzhm",sfmxCalss.mZHM),
                     new SqlParameter("@czgh",sfmxCalss.cZGH)};
                res = sqlhelper.ExecuteNonQuery(strSql, paras, CommandType.StoredProcedure);//ExecuteNonQuery为数据库操作类中的方法，传入三个参数
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
            return res;
        }
    }
}
